﻿using NExt.Handler.Base.Default;
using System.Web;

namespace NExt.Handler.Component.Default.JsSerialize
{
    public class HandlerFactory: Base.JsHandlerFactory
    {
        protected override IContentBuilder BuildContentBuilder()
        {
            INExtScriptGenerator constructorScriptGenerator = new ConstructorScriptGenerator();
            INExtScriptGenerator constructoRemoteInstanceDecoratorScriptGenerator = new ConstructoRemoteInstanceDecoratorScriptGenerator();
            INExtScriptGenerator constructorVariableBindDecoratorScriptGenerator = new ConstructorVariableBindDecoratorScriptGenerator();
            INExtScriptGenerator inheritanceScriptGenerator = new InheritanceScriptGenerator();
            INExtScriptGenerator methodScriptGenerator = new MethodScriptGenerator();
            INExtScriptGenerator remoteMethodScriptGenerator = new RemoteMethodScriptGenerator();
            INExtScriptGenerator typeRegistrationScriptGenerator = new TypeRegistrationScriptGenerator();

            INExtScriptGenerator nextScriptGenerator = new CompositeNExtScriptGenerator(
                    constructorScriptGenerator,
                    constructoRemoteInstanceDecoratorScriptGenerator,
                    constructorVariableBindDecoratorScriptGenerator,
                    inheritanceScriptGenerator,
                    methodScriptGenerator,
                    remoteMethodScriptGenerator,
                    typeRegistrationScriptGenerator
            );

            IContentBuilder nextObjectContentBuilder = new NExtObjectContentBuilder(nextScriptGenerator);
            IContentBuilder staticContentBuilder = new StaticContentBuilder();
            IContentBuilder compositeContentBuilder = new CompositeContentBuilder(nextObjectContentBuilder, staticContentBuilder);
            return compositeContentBuilder;
        }

        public override bool CanHandle(HttpContext context, string requestType, string url, string pathTranslated)
        {
            bool canHandle = (requestType == "GET");
            return canHandle;
        }
    }
}
